package com.kefu.call.vo;

import java.util.List;

import javax.validation.constraints.Size;

import lombok.*;
import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kefu.call.model.ActivityInventoryInfo;
import com.kefu.common.context.KefuContext;
import com.kefu.common.mybatis.Order;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@Data
@ToString(callSuper = true)
@ApiModel("分配活动清单")
public class ActivityInventoryInfoAssignmentVo {
	@ApiModelProperty(name = "assignmentType", value = "分配类型",
			example="1",notes= "1 简单分配 按照清单分配，2高级分配 根据查询条件分配")
	int assignmentType;

	@ApiModelProperty(name = "simpleAssignment", value = "按照清单分配",
			notes="按照用户的需要分配的清单数量，从上到下依次分配，不足的跳过")
	SimpleAssignmentVo simpleAssignment;

	@ApiModelProperty(name = "advancedAssignment", value = "按照查询条件分配")
	AdvancedAssignmentVo advancedAssignment;

	@Data
	@ToString(callSuper = true)
	@ApiModel(description = "简单分配")
	public static class SimpleAssignmentVo {
		@Size(min=1)
		@ApiModelProperty(name = "users", value = "分配用户")
		List<AssignmentUserVo> users;
		@Size(min=1)
		@ApiModelProperty(name = "inventoryIds", value = "待分配清单")
		List<String> inventoryIds;
	}
		
	@Data
	@ToString(callSuper = true)
	@ApiModel(description = "分配用户")
	public static class AssignmentUserVo {
		@ApiModelProperty("用户ID")
		String userId;
		@ApiModelProperty("用户名称")
		String userName;
		@Size(min=1)
		@ApiModelProperty("分配数量")
		int number;
	}
		
	@Data
	@ToString(callSuper = true)
	@ApiModel(description = "高级分配")
	public static class AdvancedAssignmentVo{
		@Size(min=1)
		@ApiModelProperty(name = "users", value = "分配用户")
		List<AssignmentUserVo> users;
		@ApiModelProperty(name = "pageNo", value = "起始页码", example = "1",hidden=true)
		int pageNo = 1;
		@ApiModelProperty(name = "pageSize", value = "分配条数", example = "100")
		int pageSize = 1000;
		@ApiModelProperty(name = "orderField", value = "排序字段", example = "id")
		String orderField;
		@ApiModelProperty(name = "order", value = "排序状态", example = "ASC")
		Order order = Order.ASC;
		@ApiModelProperty(value = "活动ID")
		private String activityId;
		@ApiModelProperty(value = "创建时间")
		private Long createTime;
		@ApiModelProperty(value = "修改时间")
		private Long updateTime;
		@ApiModelProperty(value = "数据状态0 无效，1有效",hidden=true)
		private Integer dataStatus=1;
		@ApiModelProperty(value = "清单状态",example="1",allowableValues="1",notes="1 未分配，2已分配，3处理中，4预约，5处理完成，6 处理失败")
		private Integer inventoryStatus=1;
		@ApiModelProperty(value = "客户ID")
		private String customerId;
		@ApiModelProperty(value = "客户名称")
		private String customerName;

		@ApiModelProperty(hidden = true)
		public <T>QueryWrapper<ActivityInventoryInfo> getExample() {
			QueryWrapper<ActivityInventoryInfo> builder = builder();
			if (StringUtils.isNotBlank(orderField) && !orderField.equals("id")) {
				order.order(builder, orderField);
			}
			return builder;
		}

		@ApiModelProperty(hidden = true)
		public QueryWrapper<ActivityInventoryInfo> builder() {
			QueryWrapper<ActivityInventoryInfo> wrapper=Wrappers.query();
			if (createTime != null) {
				wrapper.eq("create_time", createTime);
			}

			if (updateTime != null) {
				wrapper.eq("update_time", updateTime);
			}
			if (activityId != null) {
				wrapper.eq("activity_id", activityId);
			}
			if (customerId != null) {
				wrapper.eq("customer_id", customerId);
			}
			if (customerName != null) {
				wrapper.eq("customer_name", customerName);
			}

			wrapper.eq("data_status", 1);
			wrapper.eq("inventory_status", 1);
			wrapper.eq("tenant_id", KefuContext.getKefuContext().getTenantId());

			return wrapper;
		}
	}

	@Data
	@AllArgsConstructor
	@Builder
	@NoArgsConstructor
	@ToString(callSuper = true)
	public static class AssignmentResultVo {
		List<String> message;
		List<ActivityInventoryInfo> list;
	}
}